<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    .red{
      border: 1px solid red;
    }
  </style>
</head>
<body>
<form action="/valid_check" th:object="${stu2}">
  name: <input type="text" th:field="*{name}" th:errorclass="red"><br>
  <p th:if="${#fields.hasErrors('name')}" th:errors="*{name}"></p>
  java: <input type="text" th:field="*{java}" th:errorclass="red"><br>
  math: <input type="text" th:field="*{math}" th:errorclass="red"><br>
  age: <input type="text" th:field="*{age}" th:errorclass="red"><br>
  address.city: <input type="text" th:field="*{address.city}" th:errorclass="red"><br>
  <input type="submit">
  <ul th:if="${#fields.hasErrors('*')}">
    <li th:each="err : ${#fields.errors('*')}" th:text="${err}">Input is incorrect</li>
  </ul>
</form>
</body>
</html>